#!/usr/bin/env python3
# -*- coding: utf-8 -*-


__autho__ = "Tony.Don"
__lastupdatetime__ = "2017/09/29"
import threading

'''
class\r\n
    core.pool.pool(list)\r\n
description\r\n
    线程池\r\n
atttibute\r\n
    private __poolist__\r\n
        type:[]\r\n
        default:None\r\n
        description:线程列表\r\n
    private __lock__\r\n
        type:threading.Lock()\r\n
        defautl:threading.Lock()\r\n
        description:同步锁\r\n
'''
class pool(list):
    __poollist__=None
    #__lock__=threading.Lock()
    def __init__(self):
        self.__poollist__=[]
    def push(self,args):
        '''
        Feature\r\n
            push(self,args)\r\n
        Description\r\n
            入栈\r\n
        Args\r\n
            args\r\n
                type:threading.Thread\r\n
                description:线程\r\n
        '''
        #self.__lock__.acquire()
        self.__poollist__.append(args)
        #self.__lock__.release()
    
    def pop(self):
        '''
        Feature\r\n
            pop(self)\r\n
        Description\r\n
            出栈\r\n
        Return\r\n
            true:threading.Thread\r\n
            false:None\r\n
        '''
        #self.__lock__.acquire()
        try:
            if len(self.__poollist__)>0:
                result=self.__poollist__[0]
                del self.__poollist__[0]
                return result
            else:
                return None
        finally:
            pass
            #self.__lock__.release()

    def dispose(self,args):
        '''
        Feature\r\n
            dispose(self,args)\r\n
        Description\r\n
            回收线程资源\r\n
        Args\r\n
            args\r\n
                type:threading.Thread\r\n
                description:线程  \r\n
        '''
        try:
            #todo 线程释放资源
            pass
        except:
            pass
        self.push(args)
    
    def getCount(self):
        '''
        Feature\r\n
            getCount(self)\r\n
        Description\r\n
            获取线程数量\r\n
        Return\r\n
            int\r\n
        '''
        #self.__lock__.acquire()
        try:
            if self.__poollist__:
                return len(self.__poollist__)
            else:
                return 0
        finally:
            pass
            #self.__lock__.release()